package org.groupg.practice;

import org.mapdb.*;

public class AtomicOperationsExample {
    public static void main(String[] args) {
        DB db = DBMaker.memoryDB().make();

        // 创建原子整数
        Atomic.Integer counter = db.atomicInteger("pageViews").createOrOpen();

        // 初始值
        System.out.println("Initial value: " + counter.get());

        // 增加计数
        counter.incrementAndGet();
        counter.addAndGet(5);

        System.out.println("After increments: " + counter.get());

        // 使用事务进行原子操作

        System.out.println("After transaction: " + counter.get());

        db.close();
    }
}